<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>分院管理</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="/system_assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="/system_assets/css/style.css" rel="stylesheet">
	<link href="/system_assets/css/font-awesome.css" rel="stylesheet">
    <link rel="stylesheet" href="/plugins/SweetAlert/sweetalert.css" />
</head>
<body>
	<div class="container-fluid">
		<div class="om-ctl-mes">
			<div class="title">
				<div class="col-xs-12"><span class="fa fa-list-ul"> 系统设置</span><b class="fa fa-caret-right"></b><i>分院管理</i></div>
			</div>
			<div class="seltemple">
				<div class="col-xs-12">
					<form class="form-inline" method="get" action="/admin_departments">
					<div class="col-xs-3 mes-search fygl-search"><label>关键词搜索</label><input type="text" placeholder="部门名称" name="introduce" value="<?=$pIntroduce?>"><button id="search" type="button">搜索</button></div>
					<div class="col-xs-3 mes-btn fygl-btn" id="off-btn"><p>新增分院</p></div>
				</form>
				</div>
			</div>
			<div  class="mes-conttent col-xs-12">
				<table class="table fygl-table">
	              <thead>
	             	<tr>
			        <th>编号</th>
			        <th>部门编码</th>
			        <th>部门名称</th>
			        <th>部门电话</th>
			        <th>部门地址</th>
			        <th>添加时间</th>
			        <th>添加人员</th>
			        <th>操作</th>
		            </tr>
	              </thead>
	             <tbody>
	             <?foreach($tDatas as $tRow){?>
		            <tr>
		           	 <td><?=$tRow['id']?></td>
		           	 <td><?=$tRow['num']?></td>
			         <td><?=$tRow['introduce']?></td>
			         <td><?=$tRow['phone']?></td>
			         <td><span class="say"><?=$tRow['address']?></span><small class="hiddendiv"></small></td>
			         <td><?=date('Y-m-d H:i',$tRow['created'])?></td>
			         <td><span>张院长</span><small class="hiddendiv"></small></td>
			         <td>
                     <button type="button" class="editBtn" data="<?=$tRow['id']?>">编辑</button>
			         	<button onclick="cg_confirm_del('/admin_departments/delete?id=<?=$tRow['id']?>','/admin_departments')">删除</button>
			         </td>
		           </tr>
		           <?}?>
	            </tbody>
              </table>
			</div>
		</div>
    </div>
        <script type="text/javascript" src="/system_assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="/system_assets/js/jq.js"></script>
<script src="/plugins/SweetAlert/sweetalert.min.js"></script><!--alert插件-->
<script src="/js/jquery.form.js"></script><!--form表单插件-->
    <script>
    	$('#search').click(function(){
	    $('form').submit();
		});
$(function(){
//提交
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
        timeout : 3000    // 限制请求的时间，当请求大于3秒后，跳出请求
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
        cg_alert_add(responseText,'/admin_departments','/admin_departments/');
    }
function cg_alert_add(obj,list_url,add_url){
    if(obj.status == 1){
        swal({
            title: obj.msg,
            confirmButtonText:'继续添加',
            confirmButtonColor: "#DD6B55",
            showCancelButton: true,
            cancelButtonText:'返回列表',
            type: "success",
        },function(isConfirm){
            if (isConfirm) {
                location.href = add_url;
            }else{
                location.href = list_url;
            }
        });
    }else{
        swal(obj.msg,'','error');
    }

}
      var offalert="<div class='off-alert'></div>",
        html = "<div class='mark'></div>"
                +"<form method='post' class='form-incline addform' action='/admin_departments/add' class='editDepartments'>"
               +"<div class='off-alert'>"
                  +"<h3>新增分院<span id='close'>×</span></h3>"
                  +"<div class='inputs'><label>部门名称</label><input type='text' name='introduce'><label>部门编码</label><input type='text' name='num'><label>部门电话</label><input type='text' name='phone'><label>部门所在地</label><input type='text' name='address'></div>"
                  +"<div class='savecancel'><button type='button' id='add-btn'>保存</button><button type='button' id='addcancle'>取消</button></div>"
          +"</div>"
                    +"</form>";
       $("body").prepend($(html))
       $(".mark").css("height",$(document).height()+"px")       
   $(".mark").addClass('hidden')    
   $(".off-alert").addClass('hidden')
   $('#addcancle').click(function(){
        location.href="/admin_departments";
   });
      $("#off-btn").click(function(){
           $('.mark').show()
           $('.off-alert').show()
           $(".off-alert").removeClass('hidden')
           $(".mark").removeClass('hidden')
            $('#add-btn').click(function(){
                $('.addform').ajaxSubmit(options);
            });       
     })
    $("#close").click(function(){
           $('.mark').hide()
           $('.off-alert').hide()
           $(".off-alert").addClass('hidden')
           $(".mark").addClass('hidden')
     })

       	$(".btns").eq(0).css({"background":"#84dfdf"})
       	  $(".btns").click(function(){
            $(this).css({"background":"#84dfdf"}).siblings().css({"background":"#fff"})
            $('.set-list').html($(this).html())
       })
       	  $(".btns").eq(0).click(function(){
       	  	$(".set-table").show()
       	  	$(".tables").hide()
       	  	$(".set-time").hide()
                  $("#set-anbtn1").show()
                  $("#set-anbtn2").hide()
       	  })
       	    $(".btns").eq(1).click(function(){
       	  	$(".set-table").hide()
       	  	$(".tables").hide()
       	  	$(".set-time").show()
                  $("#set-anbtn1").hide()
                  $("#set-anbtn2").hide()
       	  })
       	    $(".btns").eq(2).click(function(){
       	  	$(".set-table").hide()
       	  	$(".tables").show()
       	  	$(".set-time").hide()
                  $("#set-anbtn2").show()
                  $("#set-anbtn1").hide()
       	  })
     })
     $(function(){
//提交
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
        timeout : 3000    // 限制请求的时间，当请求大于3秒后，跳出请求
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
        cg_alert_edit(responseText,'/admin_departments','/admin_departments/');
    }
function cg_alert_edit(obj,list_url,edit_url){
    if(obj.status == 1){
        swal({
            title: obj.msg,
            confirmButtonText:'继续修改',
            confirmButtonColor: "#DD6B55",
            showCancelButton: true,
            cancelButtonText:'返回列表',
            type: "success",
        },function(isConfirm){
            if (isConfirm) {
                location.href = edit_url;
            }else{
                location.href = list_url;
            }
        });
    }else{
        swal(obj.msg,'','error');
    }

}
      var offalert="<div class='off-alert-edit'></div>",
        html = "<div class='mark-edit'></div>"
                +"<form method='post' class='form-incline editform' action='/admin_departments/edit' class='editDepartments'>"
               +"<div class='off-alert-edit'>"
               +"<input type='hidden' name='d_id' class='d_id' value=''>"
                  +"<h3>编辑分院<span id='edit-close'>×</span></h3>"
                  +"<div class='inputs'><label>部门名称</label><input type='text' name='introduce' class='introduce'><label>部门编码</label><input type='text' name='num' class='num'><label>部门电话</label><input type='text' name='phone' class='phone'><label>部门所在地</label><input type='text' name='address' class='address'></div>"
                  +"<div class='savecancel'><button type='button' id='edit-btn'>保存</button><button type='button' id='editcancle'>取消</button></div>"
          +"</div>"
                    +"</form>";
       $("body").prepend($(html))
       $(".mark-edit").css("height",$(document).height()+"px")       
   $(".mark-edit").addClass('hidden')    
   $(".off-alert-edit").addClass('hidden')
   $(".editBtn").each(function(){
        $(this).click(function(){
           $('.mark-edit').show()
           $('.off-alert-edit').show()
           $(".off-alert-edit").removeClass('hidden')
           $(".mark-edit").removeClass('hidden')
           var d_id = $(this).attr('data');
           $.get('/admin_departments',{d_id:d_id},function(obj){
                if(obj.status == 1){
                    var data = obj.data;
                    $('input[class="introduce"]').val(data.introduce);
                    $('input[class="num"]').val(data.num);
                    $('input[class="phone"]').val(data.phone);
                    $('input[class="address"]').val(data.address);
                    $('input[class="d_id"]').val(data.id);
                }
           });
           $("#edit-btn").click(function(){
                $('.editform').ajaxSubmit(options);
           });
        });
   });
    $("#editcancle,#edit-close").click(function(){
           $('.mark-edit').hide()
           $('.off-alert-edit').hide()
           $(".off-alert-edit").addClass('hidden')
           $(".mark-edit").addClass('hidden')
     })

     
     });
function cg_confirm_del(del_url,jump_url){
    swal({
            title: '您确定要删除吗？',
            text:'删除之后不能恢复',
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText:'确定',
            closeOnConfirm: false,
            cancelButtonText:'取消'
        },
        function(isConfirm){
            if(isConfirm){
                window.obj = '';
                $.ajax({
                    url: del_url,
                    dataType: "json",
                    async:false,
                    success: function (obj) {
                        window.obj = obj;
                    }
                });

                if(window.obj.status == 1){
                    swal({title:"删除成功!", type:"success"},function(){
                        location.href = jump_url;
                    });
                }else{
                    swal({title:window.obj.msg, type:"error"});
                }
            }
        });
}
   	</script>
</body>
</html>
